﻿
//
// Copyright (c) 2024 BPer
//
#ifndef INCLUDE_BPERUTIL_BPERAVTYPE_H_
#define INCLUDE_BPERUTIL_BPERAVTYPE_H_

#include <bperutil/BPerType.h>

    // 8 = audio
#define    BPerFrameTypeAudio 8
    // 9 = video
#define BPerFrameTypeVideo  9
    // 18 = script data
#define kNalTypeMask       0x1F

#define BPerAudioPayloadType 111
#define BPerAV1PayloadType 123
#define BPerH264PayloadType 106
#define BPerH265PayloadType 126
#define BPerMjpegPayloadType 26


#define BPer_TWCC_ID 3

#define kDefaultLowLossThreshold 0.02f
#define kDefaultHighLossThreshold 0.1f



enum{
	BPER_DATA_CHANNEL_DCEP = 50,
	BPER_DATA_CHANNEL_STRING = 51,
	BPER_DATA_CHANNEL_BINARY = 53,
	BPER_DATA_CHANNEL_STRING_EMPTY = 56,
	BPER_DATA_CHANNEL_BINARY_EMPTY = 57
};

typedef enum BPerYuvType{
    BPerYuy2,
	BPerI420,
	BPerYv12,
	BPerNv12,
	BPerNv21,
	BPerRgb,
    BPerArgb,
    BPerBgra,
	BPerP010,
    BPerP016
}BPerColorSpace;

typedef enum BPerRatate{
	BPer_Rotate0 = 0,      // No rotation.
	BPer_Rotate90 = 90,    // Rotate 90 degrees clockwise.
	BPer_Rotate180 = 180,  // Rotate 180 degrees.
	BPer_Rotate270 = 270,
}BPerRatate;
/**
 * the level for avc/h.264.
 * @see Annex A Profiles and levels, ISO_IEC_14496-10-AVC-2003.pdf, page 207.
 */
enum BPerAvcLevel
{
    BPerAvcLevelReserved = 0,

    BPerAvcLevel_1 = 10,
    BPerAvcLevel_11 = 11,
    BPerAvcLevel_12 = 12,
    BPerAvcLevel_13 = 13,
    BPerAvcLevel_2 = 20,
    BPerAvcLevel_21 = 21,
    BPerAvcLevel_22 = 22,
    BPerAvcLevel_3 = 30,
    BPerAvcLevel_31 = 31,
    BPerAvcLevel_32 = 32,
    BPerAvcLevel_4 = 40,
    BPerAvcLevel_41 = 41,
    BPerAvcLevel_5 = 50,
    BPerAvcLevel_51 = 51,
};

/**
 * Table 7-6 – Name association to slice_type
 * ISO_IEC_14496-10-AVC-2012.pdf, page 105.
 */
enum BPerAvcSliceType
{
    BPerAvcSliceTypeP   = 0,
    BPerAvcSliceTypeB   = 1,
    BPerAvcSliceTypeI   = 2,
    BPerAvcSliceTypeSP  = 3,
    BPerAvcSliceTypeSI  = 4,
    BPerAvcSliceTypeP1  = 5,
    BPerAvcSliceTypeB1  = 6,
    BPerAvcSliceTypeI1  = 7,
    BPerAvcSliceTypeSP1 = 8,
    BPerAvcSliceTypeSI1 = 9,
};


typedef enum
{
    // Unspecified
    BPerAvcNaluTypeReserved = 0,
    BPerAvcNaluTypeForbidden = 0,

    // Coded slice of a non-IDR picture slice_layer_without_partitioning_rbsp( )
    BPerAvcNaluTypeNonIDR = 1,
    // Coded slice data partition A slice_data_partition_a_layer_rbsp( )
    BPerAvcNaluTypeDataPartitionA = 2,
    // Coded slice data partition B slice_data_partition_b_layer_rbsp( )
    BPerAvcNaluTypeDataPartitionB = 3,
    // Coded slice data partition C slice_data_partition_c_layer_rbsp( )
    BPerAvcNaluTypeDataPartitionC = 4,
    // Coded slice of an IDR picture slice_layer_without_partitioning_rbsp( )
    BPerAvcNaluTypeIDR = 5,
    // Supplemental enhancement information (SEI) sei_rbsp( )
    BPerAvcNaluTypeSEI = 6,
    // Sequence parameter set seq_parameter_set_rbsp( )
    BPerAvcNaluTypeSPS = 7,
    // Picture parameter set pic_parameter_set_rbsp( )
    BPerAvcNaluTypePPS = 8,
    // Access unit delimiter access_unit_delimiter_rbsp( )
    BPerAvcNaluTypeAccessUnitDelimiter = 9,
    // End of sequence end_of_seq_rbsp( )
    BPerAvcNaluTypeEOSequence = 10,
    // End of stream end_of_stream_rbsp( )
    BPerAvcNaluTypeEOStream = 11,
    // Filler data filler_data_rbsp( )
    BPerAvcNaluTypeFilterData = 12,
    // Sequence parameter set extension seq_parameter_set_extension_rbsp( )
    BPerAvcNaluTypeSPSExt = 13,
    // Prefix NAL unit prefix_nal_unit_rbsp( )
    BPerAvcNaluTypePrefixNALU = 14,
    // Subset sequence parameter set subset_seq_parameter_set_rbsp( )
    BPerAvcNaluTypeSubsetSPS = 15,
    // Coded slice of an auxiliary coded picture without partitioning slice_layer_without_partitioning_rbsp( )
    BPerAvcNaluTypeLayerWithoutPartition = 19,
    // Coded slice extension slice_layer_extension_rbsp( )
    BPerAvcNaluTypeCodedSliceExt = 20,
}BPerAvcNaluType;

enum BPerAvcProfile
{
    BPerAvcProfileReserved = 0,

    // @see ffmpeg, libavcodec/avcodec.h:2713
    BPerAvcProfileBaseline = 66,
    // FF_PROFILE_H264_CONSTRAINED  (1<<9)  // 8+1; constraint_set1_flag
    // FF_PROFILE_H264_CONSTRAINED_BASELINE (66|FF_PROFILE_H264_CONSTRAINED)
    BPerAvcProfileConstrainedBaseline = 578,
    BPerAvcProfileMain = 77,
    BPerAvcProfileExtended = 88,
    BPerAvcProfileHigh = 100,
    BPerAvcProfileHigh10 = 110,
    BPerAvcProfileHigh10Intra = 2158,
    BPerAvcProfileHigh422 = 122,
    BPerAvcProfileHigh422Intra = 2170,
    BPerAvcProfileHigh444 = 144,
    BPerAvcProfileHigh444Predictive = 244,
    BPerAvcProfileHigh444Intra = 2192,
};

struct BPerRect{
    short x;
    short y;
    short w;
    short h;
};
struct BPerColor{
    uint8_t r;
    uint8_t g;
    uint8_t b;
};
typedef struct  {
	int32_t vpsLen;
	int32_t spsLen;
	int32_t ppsLen;
	uint8_t vps[128];
	uint8_t sps[128];
	uint8_t pps[64];
}BPerH2645Conf;

typedef struct  {
	uint8_t buffer[128];
	int32_t bufLen;
}BPerRtmpMeta;

typedef struct  {
	int32_t isInit;
	 BPerH2645Conf mp4Meta;
	//BPerRtmpMeta flvMeta;
	 BPerRtmpMeta livingMeta;
}BPerVideoMeta;


enum BPerVideoHwType{
	BPer_Hw_Soft,
	BPerV_Hw_Intel,
	BPerV_Hw_Nvdia,
	BPerV_Hw_Android
};

struct BPerMessage{
	int32_t mediaType;
	int32_t nb;
	int64_t timestamp;
	char* payload;
};

typedef struct {
	int32_t nb;
	char* bytes;
}BPerSample;

BPerSample* bPer_sample_copy(BPerSample* src);



#include <bperutil/BPerAvcType.h>
#ifdef __cplusplus
extern "C"{
#include <bperutil/BPerFrameBuffer.h>
}
#else
#include <bperutil/BPerFrameBuffer.h>
#endif
#ifdef __cplusplus
class BPerBufferManager{
public:
	BPerBufferManager();
	BPerBufferManager(int32_t num,int32_t bufsize);
	virtual ~BPerBufferManager();
	void init(int32_t num,int32_t bufsize);
	uint8_t* getBuffer();
private:
	uint8_t* m_cache;
	int32_t m_curindex;
	int32_t m_unitsize;
	int32_t m_size;
};
#endif
#endif /* INCLUDE_BPERUTIL_BPERAVTYPE_H_ */
